obsolete DEBUG_MEM (#279)
authortsteven4 <tsteven4@users.noreply.github.com>
Wed, 28 Nov 2018 01:48:17 +0000 (18:48 -0700)
committerGitHub <noreply@github.com>
Wed, 28 Nov 2018 01:48:17 +0000 (18:48 -0700)
13 files changed:
Makefile.in
cet_util.cc
csv_util.cc
csv_util.h
defs.h
gbfile.cc
gbfile.h
main.cc
mkshort.cc
tools/cleardebug [deleted file]
tools/memdebug [deleted file]
util.cc
vecs.cc

index 448d0ea94e5438e79098eec3167a775bd3f14772..d4dbfcf47e7d4f9d0a0ae17e68ff6744a4439f67 100644 (file)
@@ -56,7 +56,6 @@ LRELEASE=@LRELEASE@
 #
 #OPTIMIZATION=-O $(EXTRA_OPTIMIZATION)
 #DEBUGGING=-g $(EXTRA_DEBUGGING)
-# add -DDEBUG_MEM to turn on memory allocation logging
 GBCFLAGS=$(EXTRA_CFLAGS) $(DEBUGGING) $(BUILD_CPP) @ZLIB_CPP@ @QT_INC_OPT@$(QT_INC) \
        $(OPTIMIZATION) -DHAVE_CONFIG_H -DNEW_STRINGS
 LDFLAGS=$(EXTRA_LDFLAGS) @LDFLAGS@
@@ -143,7 +142,7 @@ WEB=@DOCDIR@
 # Declaring a target PHONY whose names matches a subdirectory can be
 # particularly important, e.g. gui.
 .PHONY: all clean tag more-clean check torture \
-install install-debug leaktest \
+install install-debug \
 dep doc \
 release-sourcecheck release-tarball release-rpm \
 cross-configure \
@@ -224,12 +223,6 @@ install-debug:
 
 # Nerdy release stuff that needs to work only on Linux.
 
-leaktest:
-       make EXTRA_CFLAGS=-DDEBUG_MEM
-       tools/cleardebug
-       ./testo
-       tools/memdebug | grep -v '^command line:'
-
 dep:
        make clean && make -j8 EXTRA_CFLAGS="-isystem /sw/include @QT_SYSINC_OPT@ $(QT_INC) -MMD"  && cat $(sort $(DEPFILES)) > /tmp/dep && rm $(DEPFILES)
        echo 'internal_styles.cc: mkstyle.sh $$(srcdir)/style/*.style' >> /tmp/dep
index c6be77ef814afcf7b124d9b0aba3705f567ba501..758dc154f03be85c9b458f1b8b4aae0224a46527 100644 (file)
@@ -94,9 +94,6 @@ cet_register_cs(cet_cs_vec_t* vec)
     vec->next = cet_cs_vec_root;
     cet_cs_vec_root = vec;
     cet_cs_vec_ct++;
-#ifdef DEBUG_MEM
-    cet_check_cs(vec);
-#endif
   }
 }
 
index 9247ba78d3eeb942ee4f1397c8bba8e12be710e0..31129cb423626ea3e57c3e5ca6790e89de586769 100644 (file)
@@ -194,7 +194,7 @@ char*
 csv_stringtrim(const char* string, const char* enclosure, int strip_max)
 {
   static const char* p1 = nullptr;
-  char* tmp = xxstrdup(string,file,line);
+  char* tmp = xstrdup(string);
   size_t elen;
   int stripped = 0;
 
index 25925194f5a7dacf8c9c1a6d5bf21d31e8854306..214c3e1420c2ec9c3846a0df8318b4046943b0a4 100644 (file)
@@ -26,12 +26,7 @@ class QTextStream;
 /* function prototypes */
 
 char*
-#ifndef DEBUG_MEM
 csv_stringtrim(const char* string, const char* enclosure, int strip_max);
-#else
-CSV_STRINGTRIM(const char* string, const char* enclosure, int strip_max, DEBUG_PARAMS);
-#define csv_stringtrim( s, e,m ) CSV_STRINGTRIM( s, e, m, __FILE__, __LINE__)
-#endif
 QString csv_stringtrim(const QString& source, const QString& enclosure);
 
 char*
@@ -45,12 +40,7 @@ human_to_dec(const QString& instr, double* outlat, double* outlon, int which) {
 }
 
 char*
-#ifndef DEBUG_MEM
 csv_stringclean(const char* string, const char* chararray);
-#else
-CSV_STRINGCLEAN(const char* string, const char* chararray,DEBUG_PARAMS);
-#define csv_stringclean(s,c) CSV_STRINGCLEAN(s,c,__FILE__,__LINE__)
-#endif
 QString csv_stringclean(const QString& string, const QString& chararray);
 
 void
diff --git a/defs.h b/defs.h
index 4ea3ac1b9a73ffd3260c0a62eb0d07f37ad71f7f..b4aa31267ec6fb124abb2baa4f7c642c59e850d4 100644 (file)
--- a/defs.h
+++ b/defs.h
@@ -815,13 +815,7 @@ typedef void (*ff_exit)(void);
 typedef void (*ff_writeposn)(Waypoint*);
 typedef Waypoint* (*ff_readposn)(posn_status*);
 
-#ifndef DEBUG_MEM
 char* get_option(const char* iarglist, const char* argname);
-#else
-#define DEBUG_PARAMS const char *file, const int line
-char* GET_OPTION(const char* iarglist, const char* argname, DEBUG_PARAMS);
-#define get_option(iarglist, argname) GET_OPTION(iarglist, argname, __FILE__, __LINE__)
-#endif
 
 void xcsv_setup_internal_style(const char* style_buf);
 void xcsv_read_internal_style(const char* style_buf);
@@ -851,16 +845,9 @@ typedef struct {
 } mkshort_handle_imp;
 typedef mkshort_handle_imp* short_handle;
 
-#ifndef DEBUG_MEM
 char* mkshort(short_handle,  const char*);
 QString mkshort(short_handle,  const QString&);
 short_handle mkshort_new_handle(void);
-#else
-char* MKSHORT(short_handle,  const char*, DEBUG_PARAMS);
-short_handle MKSHORT_NEW_HANDLE(DEBUG_PARAMS);
-#define mkshort( a, b) MKSHORT(a,b,__FILE__, __LINE__)
-#define mkshort_new_handle() MKSHORT_NEW_HANDLE(__FILE__,__LINE__)
-#endif
 QString mkshort_from_wpt(short_handle h, const Waypoint* wpt);
 void mkshort_del_handle(short_handle* h);
 void setshort_length(short_handle, int n);
@@ -1002,7 +989,6 @@ void disp_formats(int version);
 const char* name_option(long type);
 void printposn(const double c, int is_lat);
 
-#ifndef DEBUG_MEM
 void* xcalloc(size_t nmemb, size_t size);
 void* xmalloc(size_t size);
 void* xrealloc(void* p, size_t s);
@@ -1010,38 +996,7 @@ void xfree(const void* mem);
 char* xstrdup(const QString& s);
 char* xstrndup(const char* str, size_t sz);
 char* xstrappend(char* src, const char* newd);
-#define xxcalloc(nmemb, size, file, line) xcalloc(nmemb, size)
-#define xxmalloc(size, file, line) xmalloc(size)
-#define xxrealloc(p, s, file, line) xrealloc(p,s)
-#define xxfree(mem, file, line) xfree(mem)
-#define xxstrdup(s, file, line) xstrdup(s)
 char* xstrdup(const char* s);
-#define xxstrappend(src, addon, file, line) xstrappend(src, addon)
-#else /* DEBUG_MEM */
-void* XCALLOC(size_t nmemb, size_t size, DEBUG_PARAMS);
-void* XMALLOC(size_t size, DEBUG_PARAMS);
-void* XREALLOC(void* p, size_t s, DEBUG_PARAMS);
-void XFREE(void* mem, DEBUG_PARAMS);
-char* XSTRDUP(const char* s, DEBUG_PARAMS);
-char* XSTRNDUP(const char* src, size_t size, DEBUG_PARAMS);
-char* XSTRAPPEND(char* src, const char* addon, DEBUG_PARAMS);
-void debug_mem_open();
-void debug_mem_output(char* format, ...);
-void debug_mem_close();
-#define xcalloc(nmemb, size) XCALLOC(nmemb, size, __FILE__, __LINE__)
-#define xmalloc(size) XMALLOC(size, __FILE__, __LINE__)
-#define xrealloc(p, s) XREALLOC(p,s,__FILE__,__LINE__)
-#define xfree(mem) XFREE(mem, __FILE__, __LINE__)
-#define xstrdup(s) XSTRDUP(s, __FILE__, __LINE__)
-#define xstrndup(s, z) XSTRNDUP(s, z, __FILE__, __LINE__)
-#define xstrappend(src,addon) XSTRAPPEND(src, addon, __FILE__, __LINE__)
-#define xxcalloc XCALLOC
-#define xxmalloc XMALLOC
-#define xxrealloc XREALLOC
-#define xxfree XFREE
-#define xxstrdup XSTRDUP
-#define xxstrappend XSTRAPPEND
-#endif /* DEBUG_MEM */
 
 FILE* xfopen(const char* fname, const char* type, const char* errtxt);
 
index bc5f36abf19f695dd564358d0644c14a534c50cf..e4561cd9065ae3f434ed7b791160aa3af3b67b51 100644 (file)
--- a/gbfile.cc
+++ b/gbfile.cc
@@ -581,11 +581,7 @@ gbfopen(const QString& filename, const char* mode, const char* module)
 
   file->fileopen(file, mode);
 
-#ifdef DEBUG_MEM
-  file->buffsz = 1;
-#else
   file->buffsz = 256;
-#endif
   file->buff = (char*) xmalloc(file->buffsz);
 
   return file;
index 8979ee5ef4f77873bf7a7112dc5dc7e439648810..10a0cad782fc29bdab86c6e21e9c741931260bd7 100644 (file)
--- a/gbfile.h
+++ b/gbfile.h
@@ -46,9 +46,6 @@ typedef gbsize_t (*gbfwrite_cb)(const void* buf, const gbsize_t size, const gbsi
 typedef int (*gbfungetc_cb)(const int c, gbfile* self);
 
 typedef struct gbfile_s {
-#ifdef DEBUG_MEM
-  void*   dummy;       /* ZERO pointer for stdio oop's */
-#endif
   union {
     FILE* std;
     unsigned char* mem;
diff --git a/main.cc b/main.cc
index 0c56985fa6108368c168162d579c621f75808bab..575659be3a41d56bbc670fba7c65b16b58c44f6e 100644 (file)
--- a/main.cc
+++ b/main.cc
@@ -278,15 +278,6 @@ main(int argc, char* argv[])
   gpsbabel_now = time(nullptr);                        /* gpsbabel startup-time */
   gpsbabel_time = current_time().toTime_t();                   /* same like gpsbabel_now, but freezed to zero during testo */
 
-#ifdef DEBUG_MEM
-  debug_mem_open();
-  debug_mem_output("command line: ");
-  for (int i = 1; i < qargs.size(); i++) {
-    debug_mem_output("%s ", qPrintable(qargs.at(i)));
-  }
-  debug_mem_output("\n");
-#endif
-
   if (gpsbabel_time != 0) {    /* within testo ? */
     global_opts.inifile = inifile_init(QString(), MYNAME);
   }
@@ -735,9 +726,6 @@ main(int argc, char* argv[])
   exit_filter_vecs();
   inifile_done(global_opts.inifile);
 
-#ifdef DEBUG_MEM
-  debug_mem_close();
-#endif
   exit(0);
 }
 
index 99f0f1ab7d1debaa48abbcbc7c044d956d431143..86a2a061d5a2fb25c475e8512028d78314caacf1 100644 (file)
@@ -81,13 +81,9 @@ unsigned int hash_string(const char* key)
 }
 
 short_handle
-#ifdef DEBUG_MEM
-MKSHORT_NEW_HANDLE(DEBUG_PARAMS)
-#else
 mkshort_new_handle()
-#endif
 {
-  mkshort_handle_imp* h = (mkshort_handle_imp*) xxcalloc(sizeof *h, 1, file, line);
+  mkshort_handle_imp* h = (mkshort_handle_imp*) xcalloc(sizeof *h, 1);
 
   for (int i = 0; i < PRIME; i++) {
     QUEUE_INIT(&h->namelist[i]);
@@ -370,11 +366,7 @@ setshort_is_utf8(short_handle h, const int is_utf8)
 }
 
 char*
-#ifdef DEBUG_MEM
-MKSHORT(short_handle h, const char* istring, DEBUG_PARAMS)
-#else
 mkshort(short_handle h, const char* istring)
-#endif
 {
   char* ostring;
   char* tstring;
@@ -385,7 +377,7 @@ mkshort(short_handle h, const char* istring)
   if (hdl->is_utf8) {
     ostring = cet_utf8_strdup(istring);  /* clean UTF-8 string */
   } else {
-    ostring = xxstrdup(istring, file, line);
+    ostring = xstrdup(istring);
   }
 
   /*
@@ -406,7 +398,7 @@ mkshort(short_handle h, const char* istring)
   if ((strlen(ostring) > hdl->target_len + 4) &&
       (strncmp(ostring, "The ", 4) == 0 ||
        strncmp(ostring, "the ", 4) == 0)) {
-    char* nstring = xxstrdup(ostring + 4, file, line);
+    char* nstring = xstrdup(ostring + 4);
     xfree(ostring);
     ostring = nstring;
   }
@@ -424,7 +416,7 @@ mkshort(short_handle h, const char* istring)
     /*
      * Eliminate Whitespace
      */
-    tstring = xxstrdup(ostring, file, line);
+    tstring = xstrdup(ostring);
     l = strlen(tstring);
     cp = ostring;
     for (i=0; i<l; i++) {
@@ -451,7 +443,7 @@ mkshort(short_handle h, const char* istring)
   /*
    * Eliminate chars on the blacklist.
    */
-  tstring = xxstrdup(ostring, file, line);
+  tstring = xstrdup(ostring);
   l = strlen(tstring);
   cp = ostring;
   for (i=0; i<l; i++) {
diff --git a/tools/cleardebug b/tools/cleardebug
deleted file mode 100755 (executable)
index 1ee27e1..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-#!/bin/sh
-
-rm /tmp/gpsbabel.debug
-touch /tmp/gpsbabel.debug
-
diff --git a/tools/memdebug b/tools/memdebug
deleted file mode 100755 (executable)
index 8748799..0000000
+++ /dev/null
@@ -1,74 +0,0 @@
-#!/usr/bin/perl
-
-sub alloc {
-    my $addr = shift;
-    my $file = shift;
-    my $line = shift;
-
-    if ( $arena{$addr} ) {
-        ($ofile,$oline) = @{$arena{$addr}};
-        print( "duplicate allocation $addr at $file $line\n  allocated at $ofile $oline\n" );
-    }
-    if ( $freed{$addr} ) {
-       delete $freed{$addr};
-    }
-    $arena{$addr} = [$file,$line];
-}
-
-sub free {
-    my $addr = shift;
-    my $file = shift;
-    my $line = shift;
-    
-    if ( $arena{$addr} ) {
-        $freed{$addr} = [$arena{$addr}->[0], $arena{$addr}->[1], $file, $line];
-        delete $arena{$addr};
-    }
-    else {
-        if ($freed{$addr}) {
-            ($afile,$aline,$ffile,$fline) = @{$freed{$addr}};
-            print( "double free $addr at $file $line\n  allocated at $afile $aline\n  last freed at $ffile $fline\n" );
-        }
-        else {
-            print( "freeing unallocated $addr at $file $line\n" );
-        }
-    }
-}
-
-sub unfreed {
-    for $addr (keys %arena) {
-        ($file,$line)=@{$arena{$addr}};
-        print( "unfreed $addr allocated at $file $line\n" );
-    }
-    undef %arena;
-    undef %freed;
-}
-
-open(FILE, "</tmp/gpsbabel.debug");
-
-while (<FILE>) {
-    chomp; 
-    @args = split(', ',$_);
-    if ($args[0] eq 'malloc') {
-        &alloc($args[1], $args[3], $args[4]);
-    }
-    if ($args[0] eq 'calloc') {
-        &alloc($args[1], $args[4], $args[5]);
-    }
-    if ($args[0] eq 'strdup') {
-        &alloc($args[1], $args[3], $args[4]);
-    }
-    if ($args[0] eq 'realloc') {
-        &free($args[2], $args[4], $args[5]);
-        &alloc($args[1], $args[4], $args[5]);
-    }
-    if ($args[0] eq 'free') {
-        &free($args[1], $args[2], $args[3]);
-    }
-    if ($args[0] =~ m/^command/) {
-        &unfreed;
-        print "$args[0]\n";
-    }
-}
-&unfreed;
-close(FILE);
diff --git a/util.cc b/util.cc
index ab578925c639a852a64d0a29b99a8984cf9baafd..78986e434070f3786beebd0a23598ace85423e03 100644 (file)
--- a/util.cc
+++ b/util.cc
 #endif
 #endif
 
-#ifdef DEBUG_MEM
-#define DEBUG_FILENAME "/tmp/gpsbabel.debug"
-
-static FILE* debug_mem_file = NULL;
-void
-debug_mem_open()
-{
-  debug_mem_file = xfopen(DEBUG_FILENAME, "a", "debug");
-}
-
-void
-debug_mem_output(char* format, ...)
-{
-  va_list args;
-  va_start(args, format);
-  if (debug_mem_file) {
-    vfprintf(debug_mem_file, format, args);
-    fflush(debug_mem_file);
-  }
-  va_end(args);
-}
-
-void
-debug_mem_close()
-{
-  if (debug_mem_file) {
-    fclose(debug_mem_file);
-  }
-  debug_mem_file = NULL;
-}
-#endif
-
 void*
-#ifdef DEBUG_MEM
-XMALLOC(size_t size, DEBUG_PARAMS)
-#else
 xmalloc(size_t size)
-#endif
 {
   void* obj = malloc(size);
 
-#ifdef DEBUG_MEM
-  debug_mem_output("malloc, %x, %d, %s, %d\n",
-                   obj, size, file, line);
-#endif
   if (!obj) {
     fatal("gpsbabel: Unable to allocate %ld bytes of memory.\n", (unsigned long) size);
   }
@@ -98,17 +58,9 @@ xmalloc(size_t size)
 }
 
 void*
-#ifdef DEBUG_MEM
-XCALLOC(size_t nmemb, size_t size, DEBUG_PARAMS)
-#else
 xcalloc(size_t nmemb, size_t size)
-#endif
 {
   void* obj = calloc(nmemb, size);
-#ifdef DEBUG_MEM
-  debug_mem_output("calloc, %x, %d, %d, %s, %d\n",
-                   obj, nmemb, size, file, line);
-#endif
 
   if (!obj) {
     fatal("gpsbabel: Unable to allocate %ld units of %ld bytes of memory.\n", (unsigned long) nmemb, (unsigned long) size);
@@ -118,31 +70,15 @@ xcalloc(size_t nmemb, size_t size)
 }
 
 void
-#ifdef DEBUG_MEM
-XFREE(const void* mem, DEBUG_PARAMS)
-#else
 xfree(const void* mem)
-#endif
 {
   free(const_cast<void*>(mem));
-#ifdef DEBUG_MEM
-  debug_mem_output("free, %x, %s, %d\n",
-                   mem, file, line);
-#endif
 }
 
 char*
-#ifdef DEBUG_MEM
-XSTRDUP(const char* s, DEBUG_PARAMS)
-#else
 xstrdup(const char* s)
-#endif
 {
   char* o = s ? strdup(s) : strdup("");
-#ifdef DEBUG_MEM
-  debug_mem_output("strdup, %x, %x, %s, %d\n",
-                   o, s, file, line);
-#endif
 
   if (!o) {
     fatal("gpsbabel: Unable to allocate %ld bytes of memory.\n", (unsigned long) strlen(s));
@@ -160,11 +96,7 @@ char* xstrdup(const QString& s)
  * Duplicate at most sz bytes in str.
  */
 char*
-#ifdef DEBUG_MEM
-XSTRNDUP(const char* str, size_t sz, DEBUG_PARAMS)
-#else
 xstrndup(const char* str, size_t sz)
-#endif
 {
   size_t newlen = 0;
   const char* cin = str;
@@ -182,20 +114,9 @@ xstrndup(const char* str, size_t sz)
 }
 
 void*
-#ifdef DEBUG_MEM
-XREALLOC(void* p, size_t s, DEBUG_PARAMS)
-#else
 xrealloc(void* p, size_t s)
-#endif
 {
   char* o = (char*) realloc(p, s);
-#ifdef DEBUG_MEM
-  if (p != NULL) {
-    debug_mem_output("realloc, %x, %x, %x, %s, %d\n", o, p, s, file, line);
-  } else {
-    debug_mem_output("malloc, %x, %d, %s, %d\n", o, s, file, line);
-  }
-#endif
 
   if (!o) {
     fatal("gpsbabel: Unable to realloc %ld bytes of memory.\n", (unsigned long) s);
@@ -208,21 +129,17 @@ xrealloc(void* p, size_t s)
 * For an allocated string, realloc it and append 's'
 */
 char*
-#ifdef DEBUG_MEM
-XSTRAPPEND(char* src, const char* newd, DEBUG_PARAMS)
-#else
 xstrappend(char* src, const char* newd)
-#endif
 {
   if (!src) {
-    return xxstrdup(newd, file, line);
+    return xstrdup(newd);
   }
   if (!newd) {
-    return xxstrdup(src, file, line);
+    return xstrdup(src);
   }
 
   size_t newsz = strlen(src) + strlen(newd) + 1;
-  src = (char*) xxrealloc(src, newsz, file, line);
+  src = (char*) xrealloc(src, newsz);
   strcat(src, newd);
 
   return src;
@@ -325,11 +242,7 @@ xvasprintf(char** strp, const char* fmt, va_list ap)
 {
   /* From http://perfec.to/vsnprintf/pasprintf.c */
   /* size of first buffer malloc; start small to exercise grow routines */
-#ifdef DEBUG_MEM
-# define       FIRSTSIZE       64
-#else
 # define       FIRSTSIZE       1
-#endif
   char* buf = nullptr;
   char* newbuf;
   size_t nextsize = 0;
diff --git a/vecs.cc b/vecs.cc
index ad18c2780f9e50d14efe5b834ccfb801f92d528c..7267cc80b82ef3d44719cd1c4c7f8d4b2956aa17 100644 (file)
--- a/vecs.cc
+++ b/vecs.cc
@@ -1387,11 +1387,7 @@ find_vec(const char* vecname, const char** opts)
  * Modelled approximately after getenv.
  */
 char*
-#ifdef DEBUG_MEM
-GET_OPTION(const char* iarglist, const char* argname, DEBUG_PARAMS)
-#else
 get_option(const char* iarglist, const char* argname)
-#endif
 {
   const size_t arglen = strlen(argname);
   char* rval = nullptr;
@@ -1425,7 +1421,7 @@ get_option(const char* iarglist, const char* argname)
    * this data.
    */
   if (rval) {
-    rval = xxstrdup(rval,file, line);
+    rval = xstrdup(rval);
   }
   xfree(arglist);
   return rval;